;
(function() {
    var oldGuid = '';
    var oldPaId = '';
    var _this = cafa = {
        /**
         * 初始化学院导航
         */
        initCollegeNav: function() {
            var swiper = new Swiper('#collegeNav .swiper-container', {
                slidesPerView: 'auto',
                scrollbar: '.swiper-scrollbar',
                onInit: function(swiper) {
                    var guid = util.getQueryString('guid');
                    var paId = util.getHashString('pa_id');
                    oldGuid = guid;
                    oldPaId = paId;
                    for (var i = 0; i < swiper.slides.length; i++) {
                        var nav = swiper.slides.eq(i).find('a');
                        if (nav.attr('data-guid') === guid && paId === nav.attr('data-paid')) {
                            $('#collegeNav .swiper-container a').removeClass('on').eq(i).addClass('on');
                            swiper.slideTo(i > 0 ? i - 1 : i);
                            break;
                        }
                    }
                },
                onClick: function(swiper) {
                    // guid相同的情况
                    var guid = util.getQueryString('guid');
                    var paId = util.getHashString('pa_id');
                    var krpanoSWFObject = document.getElementById('krpanoSWFObject');
                    if (oldGuid === guid && oldPaId !== paId && krpanoSWFObject) {
                        krpanoSWFObject.call('loadscene("scene_' + paId + '");');
                    }
                    var index = $(swiper.clickedSlide).index();
                    swiper.slides.find('a').removeClass('on');
                    $(swiper.clickedSlide).find('a').addClass('on');
                    swiper.slideTo(index > 0 ? index - 1 : index);
                    oldGuid = guid;
                    oldPaId = paId;
                }
            });
            $('#btnSwitch').on('click', function(e) {
                e.stopPropagation();
                $('#collegeNav').addClass('on');
            });
            $('#collegeNav').on('click', function(e) {
                e.stopPropagation();
            });
        },
        /**
         * 获取学院列表
         * @param {integer} type 学院类型
         */
        getCollegeList: function(type) {
            ajax.getCollegeList({
                type: type,
                success_cb: function(res) {
                    var _this = cafa;
                    var data = res.data.list;
                    var tpl = $('#collegeNavTpl').html();
                    var html = template.render(tpl, data);
                    $('#collegeNav .swiper-wrapper').html(html);
                    _this.initCollegeNav();
                },
                fail_cb: function(err) {
                    console.error(err);
                }
            })
        },
        showPreface: function(list) {
            var guid = util.getQueryString('guid');
            for (var i = 0; i < list.length; i++) {
                if (guid == list[i].guid) {
                    window.cafaCM.initPreface();
                    $("#floorPreface").show();
                    return;
                }
            }

            $("#floorPreface").hide();
        },
        /**
         * 初始化前言介绍
         */
        initPreface: function() {
            if (util.getHashString('student_no')) {
                $("#floorPreface").hide();
                return;
            }
            window.cafaCM.initSceneList(_this.showPreface);
        },
        /**
         * 初始化
         */
        init: function() {
            var zoom = parseFloat($('body').css('zoom'));
            if (zoom) {
                $('#pano').css('zoom', 1 / zoom);
            }
            this.initPreface();
            this.getCollegeList(2);
            if (window.cafaCM) {
                cafaCM.init();
            }
            $('body').on('click', '.btn_play_video', function() {
                cafaCM.showVideo($(this).data('video'));
                cafaCM.openVideoModal();
            });
        },
    };
    cafa.init();
})();